﻿Imports NUnit.Framework
Imports SqlAnalyzer

<TestFixture()>
Public Class VariableDeclarationTests


    <SetUp()>
    Public Sub SetUp()

    End Sub

    <TearDown()>
    Public Sub TearDown()

    End Sub

    <Test()>
    Public Sub IntegerDeclarationTest()
        Dim query As String = IO.File.ReadAllText("Queries/integer_declaration.sql")
        Dim analyzer As New SqlAnalyzer(query)

        Assert.IsNotNull(analyzer("@lower"))
        Assert.AreEqual(GetType(Integer), analyzer("@lower").FrameworkType)
        Assert.AreEqual(SqlDbType.Int, analyzer("@lower").SqlDbType)
        Assert.AreEqual("int", analyzer("@lower").DeclaredType)

        Assert.IsNotNull(analyzer("@as_lower"))
        Assert.AreEqual(GetType(Integer), analyzer("@as_lower").FrameworkType)
        Assert.AreEqual(SqlDbType.Int, analyzer("@as_lower").SqlDbType)
        Assert.AreEqual("int", analyzer("@as_lower").DeclaredType)

        Assert.IsNotNull(analyzer("@as_lower_full"))
        Assert.AreEqual(GetType(Integer), analyzer("@as_lower_full").FrameworkType)
        Assert.AreEqual(SqlDbType.Int, analyzer("@as_lower_full").SqlDbType)
        Assert.AreEqual("integer", analyzer("@as_lower_full").DeclaredType)

        Assert.IsNotNull(analyzer("@lower_full"))
        Assert.AreEqual(GetType(Integer), analyzer("@as_lower_full").FrameworkType)
        Assert.AreEqual(SqlDbType.Int, analyzer("@as_lower_full").SqlDbType)
        Assert.AreEqual("integer", analyzer("@as_lower_full").DeclaredType)

        Assert.IsNotNull(analyzer("@upper"))
        Assert.AreEqual(GetType(Integer), analyzer("@upper").FrameworkType)
        Assert.AreEqual(SqlDbType.Int, analyzer("@upper").SqlDbType)
        Assert.AreEqual("INT", analyzer("@upper").DeclaredType)

        Assert.IsNotNull(analyzer("@as_upper"))
        Assert.AreEqual(GetType(Integer), analyzer("@as_upper").FrameworkType)
        Assert.AreEqual(SqlDbType.Int, analyzer("@as_upper").SqlDbType)
        Assert.AreEqual("INT", analyzer("@as_upper").DeclaredType)

        Assert.IsNotNull(analyzer("@upper_full"))
        Assert.AreEqual(GetType(Integer), analyzer("@as_upper_full").FrameworkType)
        Assert.AreEqual(SqlDbType.Int, analyzer("@as_upper_full").SqlDbType)
        Assert.AreEqual("INTEGER", analyzer("@as_upper_full").DeclaredType)

        Assert.IsNotNull(analyzer("@as_upper_full"))
        Assert.AreEqual(GetType(Integer), analyzer("@as_upper_full").FrameworkType)
        Assert.AreEqual(SqlDbType.Int, analyzer("@as_upper_full").SqlDbType)
        Assert.AreEqual("INTEGER", analyzer("@as_upper_full").DeclaredType)
    End Sub

    <Test()>
    Public Sub LongDeclarationTest()
        Dim query As String = IO.File.ReadAllText("Queries/long_declaration.sql")
        Dim analyzer As New SqlAnalyzer(query)

        Assert.IsNotNull(analyzer("@lower"))
        Assert.AreEqual(GetType(Long), analyzer("@lower").FrameworkType)
        Assert.AreEqual(SqlDbType.BigInt, analyzer("@lower").SqlDbType)
        Assert.AreEqual("bigint", analyzer("@lower").DeclaredType)

        Assert.IsNotNull(analyzer("@as_lower"))
        Assert.AreEqual(GetType(Long), analyzer("@as_lower").FrameworkType)
        Assert.AreEqual(SqlDbType.BigInt, analyzer("@as_lower").SqlDbType)
        Assert.AreEqual("bigint", analyzer("@as_lower").DeclaredType)

        Assert.IsNotNull(analyzer("@upper"))
        Assert.AreEqual(GetType(Long), analyzer("@upper").FrameworkType)
        Assert.AreEqual(SqlDbType.BigInt, analyzer("@upper").SqlDbType)
        Assert.AreEqual("BIGINT", analyzer("@upper").DeclaredType)

        Assert.IsNotNull(analyzer("@as_upper"))
        Assert.AreEqual(GetType(Long), analyzer("@as_upper").FrameworkType)
        Assert.AreEqual(SqlDbType.BigInt, analyzer("@as_upper").SqlDbType)
        Assert.AreEqual("BIGINT", analyzer("@as_upper").DeclaredType)
    End Sub
End Class
